#include <REGX52.H>
#include "NIXIE.H"
#include "Timer0.h"

unsigned char KEY=0;//全局变量KEY
unsigned char Minute=0;
unsigned char Second=0;
unsigned char Mini_Second=0;
int main()
{
	Timer0_Init();
	Timer1_Init();
	while(1)
	{
		if(KEY)
		{
			Set_Num(1,Minute/10);
			Set_Num(2,Minute%10);
			Set_Num(4,Second/10);
			Set_Num(5,Second%10);
			Set_Num(7,Mini_Second/10);
			Set_Num(8,Mini_Second%10);
		}

	}
	return 0;
}

void Timer0_Routine() interrupt 1
{
	static unsigned char Timer0_Count=0;
	static unsigned char Nixie_Count=0;
	unsigned char temp=0;
	Timer0_Count++;
	Nixie_Count++;
	TL0 = 0x66;		//设置定时初值
	TH0 = 0xFC;		//设置定时初值
	if(Timer0_Count==20)//每20毫秒扫描一次按键
	{
		Timer0_Count=0;
		temp=Key_Scan();//temp是为了防止KEY被重复赋值为0，因为当按键没有按下的时候，返回值一直为0；
		if(temp)
		{
			KEY=!KEY;
		}
	}
	if(Nixie_Count==2)//每2毫秒扫描一次数码管
	{
		Nixie_Count=0;
		Nixie_Scan();//temp是为了防止KEY被重复赋值为0，因为当按键没有按下的时候，返回值一直为0；
	}
}
void Timer1_Routine() interrupt 3//用来控制秒表
{
	static unsigned char Timer1_Count=0;
	TL1 = 0x66;		//设置定时初值
	TH1 = 0xFC;		//设置定时初值
	Timer1_Count++;
	if(Timer1_Count==10)
	{
		Timer1_Count=0;
		Mini_Second++;
		if(Mini_Second==100)
		{
			Mini_Second=0;
			Second++;
			if(Second==60)
			{
				Second=0;
				Minute++;
			}
		}
	}
}